package gw.com.android.ui.news;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.gwtsz.gts2.hx.R;

import butterknife.BindView;
import gw.com.android.ui.BaseActivity;

/**
 * 交易策略列表
 *
 * @author jett
 * @since 2018-08-30.
 */
public class StrategyNewsActivity250 extends BaseActivity {

    @BindView(R.id.strategy_pager)
    ViewPager pager;

    @Override
    protected int getLayoutView() {
        return R.layout.activity_strategy_news;
    }

    @Override
    protected void initLayoutView() {
        mTitleBar.tabs.setVisibility(View.VISIBLE);
        mTitleBar.tabs.setupWithViewPager(pager);
    }

    @Override
    protected void initViewData() {
        pager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
    }

    private class PagerAdapter extends FragmentPagerAdapter {

        private StrategyFragment strategyFragment;
        private ReferenceFragment referenceFragment;

        PagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            if (position == 0) {
                return getString(R.string.strategy_title);
            } else if (position == 1) {
                return getString(R.string.reference_title);
            }
            return super.getPageTitle(position);
        }

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                if (strategyFragment == null) {
                    strategyFragment = new StrategyFragment();
                }
                return strategyFragment;
            } else if (position == 1) {
                if (referenceFragment == null) {
                    referenceFragment = new ReferenceFragment();
                }
                return referenceFragment;
            }
            return null;
        }

        @Override
        public int getCount() {
            return 2;
        }

    }

}
